<?php
	$logger->info('Start=======================================movie wall page=======================================Start');
	$logger->debug('$_SESSION:');
	$logger->debug($_SESSION);
	$logger->debug('$_GET:');
	$logger->debug($_GET);
	$logger->debug('$skin:');
	$logger->debug($skin);
	/*'destination' => 'movie',
	'page' => 'wall',
	'key' => '5',
	'category' => 'all',
	'index' => '1'*/
	if(isset($_GET['filter'])){
		$xmlMedia = getMedia($_GET['key'], $_GET['category'], $_GET['filter']);
	}else{
		$xmlMedia = getMedia($_GET['key'], $_GET['category']);
	}
	
	$videosNodes = $xmlMedia->xpath('//Video');
	$numVideos = count($videosNodes);
	$lastIndex = ceil($numVideos / ($skin['columns'] * $skin['rows']));
	
	$thumbIcons = $homePath . '/images/thumbs/movies/';
	$thumbOverlay = $homePath . '/images/movies/wall/overlays/';
?>

<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link rel="stylesheet" type="text/css" media="screen" href="<?php echo $homePath . "/css/wall.css.php" ?>" />
		<script type="text/javascript" src="<?php echo $homePath . "/js/play.js" ?>" ></script>
	</head>
	<body>
		<table border="0" cellpadding="0" cellspacing="0" align="left">
			<tr valign="top">
				<td height="598">
					<table class="main" border="0" cellpadding="0" cellspacing="0">
						<tr valign="top">
							<td>
								<table class="main" border="0" cellpadding="0" cellspacing="0">
									<tr valign="top">
										<td align="left" valign="top" height="56" width="1">
											<img src="<?php echo $homePath . '/images/movies/wall/html' ?>/1x688.png" height="56"/>
										</td>
										<td id="indexmenuleft" width="265" valign="top" height="56" align="left">
											<table class="main" border="0" cellpadding="0" cellspacing="0">
													<tr>
														<td class="indexname"><?php 
																					if(empty($xmlMedia['title2'])){
																						echo $xmlMedia['title1'] . '->All';
																					}else{
																						echo $xmlMedia['title1'] . '->' . $xmlMedia['title2'];
																					}
																			 ?>
														 </td>
													</tr>
											</table>
										</td>
										<td id="indexmenuright" align="right">
											<table cellspacing="0" cellpadding="0" border="0" background="<?php echo $homePath . '/images/movies/wall/html' ?>/filterbg1.png">
												<tbody>
													<tr id="playpath">
														<?php
															
														?>
													</tr>
												</tbody>
											</table>
										</td>
									</tr>
								</table>
							</td>
						</tr>
						<tr align="left" valign="top">
							<td>
								<table class="movies" border="0" cellpadding="0" cellspacing="4" align="left">
									<tbody><?php
											$beginning = (int)($_GET['index'] * $skin['columns'] * $skin['rows'] - $skin['columns'] * (int)$skin['rows'] + 1);
											$end = (int)($beginning + $skin['columns'] * $skin['rows'] - 1);
											$count = 1;
											$row = 1;
											$wallIndex = 1;
											$logger->info('$beginning: ' . $beginning . ', $end: ' . $end);
											
											if($_GET['index'] == 1){
												$previousIndex = $lastIndex;
											} else {
												$previousIndex = ($_GET['index'] - 1);
											}
											
											if($_GET['index'] == $lastIndex){
												$nextIndex = 1;
											} else {
												$nextIndex = $_GET['index'] + 1;
											}
											
											foreach($xmlMedia->Video as $video){
												if($count >= $beginning AND $count <= $end){
													//$logger->info('$count: ' . $count . ', $beginning: ' . $beginning . ', $end: ' . $end . ', $count % $skin[\'columns\']): ' . ($count % $skin['columns']));
													if($count == $beginning){
														$currentRow = 'top';
														echo '<tr id=\"top\">';
													}
													// Set up down navigation.
													switch ($currentRow) {
														case 'top':
															$onkeyup = 'ONKEYUPSET="pgup"';
															$onkeydown = 'ONKEYDOWNSET="' . ($wallIndex + $skin['columns']) . '"';
															break;
														case 'middle':
															$onkeyup = 'ONKEYUPSET="' . $wallIndex - $skin['columns'] . '"';
															$onkeydown = 'ONKEYDOWNSET="' . ($wallIndex + $skin['columns']) . '"';
															break;
														case 'bottom':
															$onkeyup = 'ONKEYUPSET="' . $wallIndex - $skin['columns'] . '"';
															$onkeydown = 'ONKEYDOWNSET="pgdn"';
															break;
														default:
															break;
													}
													
													// Set left right navigation.
													switch ($count % $skin['columns']) {
														case 0:
															$onkeyleft = 'ONKEYLEFTSET="' . ($wallIndex - 1) . '"';
															$onkeyright = 'ONKEYRIGHTSET="' . ($wallIndex - $skin['columns'] + 1) . '"';
															break;
														case 1:
															$onkeyleft = 'ONKEYLEFTSET="' . ($wallIndex + $skin['columns'] - 1) . '"';
															$onkeyright = 'ONKEYRIGHTSET="' . ($wallIndex + 1) . '"';
															break;
														default:
															$onkeyleft = 'ONKEYLEFTSET="' . ($wallIndex - 1) . '"';
															$onkeyright = 'ONKEYRIGHTSET="' . ($wallIndex + 1) . '"';
															break;
													}
													
													//file:///opt/sybhttpd/localhost.drives/NETWORK_SHARE/RIP_NAS/Videos/Anime/Movies/Afro Samurai - Resurrection (2009).avi
													//$playPath = $pch['playPath'] . $pch['share1'] . '/' . ltrim($video->Media->Part['file'], '/home/ftp/media');
													//$logger->info('Play Path 1: ' . $playPath);
													
													//file:///opt/sybhttpd/localhost.drives/NETWORK_SHARE/RIP_NAS/Videos/Anime/Movies/Afro%20Samurai%20-%20Resurrection%20(2009).avi
													//$playPath = $pch['playPath'] . $pch['share1'] . '/Videos/Anime/Movies/' . ltrim($video->Media->Part['key'], '/library/parts/14807');
													//$logger->info('Play Path 2: ' . $playPath);
													
													//http://192.168.0.3:32400/library/parts/14807/Afro%20Samurai%20-%20Resurrection%20(2009).avi
													$playPath = $config['plex_url'] . $video->Media->Part['key'];
													$logger->info('Play Path 3: ' . $playPath);
													
													//http://192.168.0.3:32400/home/ftp/media/Videos/Anime/Movies/Afro Samurai - Resurrection (2009).avi
													//$playPath = $config['plex_url'] . $video->Media->Part['file'];
													//$logger->info('Play Path 4: ' . $playPath);
													
													echo '	<td align="center" background="' . plexGetImage($video['thumb'], 117, 174, 'thumbs/movies/') . '"> ';
													echo '		<a href="?destination=' . $_GET['destination'] . '&page=details&key=' . $video['key'] . '" name="' . $wallIndex . '" ' . $onkeyup . ' ' .  $onkeydown . ' ' .  $onkeyleft . ' ' .  $onkeyright . ' ONFOCUS="setPlayPath(' . $playPath . ')" />';
													echo '			<img width="117" height="174" src="' . $thumbOverlay . 'posteroverlay2.png" onfocussrc="'. $thumbOverlay . 'glassoverlay5.png" />';
													echo '		</a>';
													echo '	</td>';
													
													if($count == ($end - $skin['columns'])) {
														$currentRow = 'bottom';
														echo '</tr>';
														echo '<tr id=\"bottom\">';
													}
													
													if($count % $skin['columns'] == 0 AND $currentRow != 'bottom'){
														$currentRow = 'middle';
														$onkeyup = 'ONKEYUPSET="' . $wallIndex - $skin['columns'] . '"';
														echo '</tr>';
														echo '<tr id=\"middle\">';
													}
													$wallIndex++;
												}
												$count++;
											}
											echo '</tr>';?>
									</tbody>
								</table>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		<div class="control">
			<a href="<?php echo '?destination=' . $_GET['destination'] . '&page=wall&key=' . $_GET['key'] . '&category=all&index=' . $previousIndex ?>" name="pgup" ONFOCUSLOAD=""></a>
			<a href="<?php echo '?destination=' . $_GET['destination'] . '&page=wall&key=' . $_GET['key'] . '&category=all&index=' . $nextIndex ?>" name="pgdn" ONFOCUSLOAD=""></a>
			<a href="" id="play" TVID="Play" vod=""></a>
		</div>
	</body>
</html>
<?php
$logger->info('End=======================================movie wall page=======================================End');
?>
